home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / flxkey.exe / READKEY1.PAS < prev    next >
Pascal/Delphi Source File  |  1993-02-21  |  5KB  |  116 lines

  1.  
  2. (**********************************************************************)
  3. (* Simple program to demonstrate how to use the FlxKey unit to obtain *)
  4. (* user-data from encrypted registration-key file.                    *)
  5. (**********************************************************************)
  6.  
  7. program Read_FlxKey_Demo1;
  8. uses
  9.   Crt,
  10.   FlxKey;
  11.  
  12. var           (* Variable set by ReadFlxKey routine, that indicates   *)
  13.               (* the difference in days between the current date and  *)
  14.               (* the date encrypted into the registration-key file.   *)
  15.   DaysOld,
  16.  
  17.               (* This variable is used to check for errors returned   *)
  18.               (* by ReadFlxKey routine.                               *)
  19.   ErrorCode  : word;
  20.  
  21.               (* Encryption-code strings used to create encrypted     *)
  22.               (* registration-key file.                               *)
  23.   Ecode1,
  24.   Ecode2     : st_100;
  25.  
  26.               (* This is the full path/filename of the encrypted      *)
  27.               (* registration-key file to be decrypted.               *)
  28.   RegKeyName : st_79;
  29.  
  30.               (* Record variable to hold the data decrypted from the  *)
  31.               (* encrypted registration-key file.                     *)
  32.   TempKeyRec : rc_Flx;
  33.  
  34.               (* Main program execution block.                        *)
  35. BEGIN
  36.               (* Clear the temporary key-record variable.             *)
  37.   fillchar(TempKeyRec, sizeof(TempKeyRec), 0);
  38.  
  39.               (* Assign encryption-code strings to be used to decrypt *)
  40.               (* encrypted registration-key data.                     *)
  41.   Ecode1 := 'Apple';
  42.   Ecode2 := 'Orange';
  43.  
  44.               (* Full path/filename for the encrypted registration-   *)
  45.               (* key file to be decrypted.                            *)
  46.   RegKeyName := 'DEMO1.KEY';
  47.  
  48.               (* Decrypt the registration-key file, and retrieve it's *)
  49.               (* data.                                                *)
  50.               (* NOTE: A 10 second delay and message are present in   *)
  51.               (*       the un-registered copy of the FlxKey unit.     *)
  52.   ReadFlxKey(Ecode1, Ecode2, RegKeyName, TempKeyRec, DaysOld, ErrorCode);
  53.  
  54.               (* Clear the screen.                                    *)
  55.   clrscr;
  56.   writeln;
  57.  
  58.               (* Check for errors.                                    *)
  59.   if (ErrorCode <> 0) then
  60.     case (ErrorCode AND $FF) of
  61.        1 : writeln(' Error! One or more encryption-codes is blank.');
  62.        2 : writeln(' Error! Filename for registration-key file is blank.');
  63.        3 : writeln(' HEAP allocation error. Unable to allocate 1024 ' +
  64.                    'buffer.');
  65.        4 : writeln(' BlocWrite error.');
  66.        5 : writeln(' BlockRead error.');
  67.        6 : writeln(' Date error. PC''s system date pre-dates ' +
  68.                    'registration-key date.');
  69.        7 : writeln(' Registration-key is corrupt.');
  70.  
  71.               (* I/O error!                                           *)
  72.       16 : begin
  73.              writeln(' I/O error = ', (ErrorCode shr 8));
  74.  
  75.               (* Standard Turbo Pascal error-codes. See TP manuals,   *)
  76.               (* as there are many types of errors to check for.      *)
  77.              case (ErrorCode shr 8) of
  78.                  2 : writeln(' File not found.');
  79.                  3 : writeln(' Path not found.');
  80.                  4 : writeln(' Too many files open.');
  81.                  5 : writeln(' File access denied.');
  82.                100 : writeln(' Disk read error.');
  83.                103 : writeln(' File not open')
  84.              end  (* case (ErrorCode shr 8) of                        *)
  85.            end
  86.     end       (* case (ErrorCode AND $FF) of                          *)
  87.   else
  88.               (* Else NO errors occurred.                             *)
  89.     begin
  90.               (* Display the decrypted registration-key data.         *)
  91.       writeln('Key is ', DaysOld, ' days old');
  92.       writeln;
  93.       with TempKeyRec do
  94.         begin
  95.           writeln(' FirstName    = ', FirstName);
  96.           writeln(' LastName     = ', LastName);
  97.           writeln(' Address1     = ', Address1);
  98.           writeln(' Address2     = ', Address2);
  99.           writeln(' Address3     = ', Address3);
  100.           writeln(' AppName      = ', AppName);
  101.           writeln(' Version      = ', Version);
  102.           writeln(' Serial Num   = ', Serial);
  103.  
  104.               (* Standard TP "UnPackTime" and "PackTime" routines     *)
  105.               (* can be used to manipulate "packed date" data.        *)
  106.           writeln(' Packed Date  = ', Date);
  107.  
  108.           writeln(' Access Level = ', Access);
  109.  
  110.           writeln(' MiscData     = ', MiscData)
  111.         end
  112.     end
  113. END.
  114.  
  115.  
  116.